package com.cssl.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cssl.pojo.AttStaffPerformance;
import com.cssl.serice.AttStaffPerformanceSerice;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
public class AttStaffPerformanceController {
    @Resource
   private   AttStaffPerformanceSerice  attStaffPerformanceSerice;

     //员工考评
        @RequestMapping("/Aquery")
    public IPage<Map<String,Object>> Aquery(String name, String kname, String date, Integer pageIndex, Integer pageSize){
            System.out.println("insdex"+pageIndex+"size"+pageSize+"data"+date);
        if (pageIndex == null){
            pageIndex =1;
        }
            IPage<Map<String,Object>> page=attStaffPerformanceSerice.Aquery(new Page<AttStaffPerformance>(pageIndex,pageSize),
                new QueryWrapper<AttStaffPerformance>()
                .like(name !=null,"s.name",name).like(kname !=null,"ss.name",kname)
                        .like(date !=null,"a.createtime",date));
        return  page;
    }


    //添加 //修改
    @RequestMapping("/Ainsert")
    public boolean Ainsert(AttStaffPerformance attStaffPerformance){
        return attStaffPerformanceSerice.saveOrUpdate(attStaffPerformance);
    }


    //修改查询
    @RequestMapping("/Adgcx")
    public AttStaffPerformance Adgcx(int id){

            return  attStaffPerformanceSerice.getById(id);
    }
    //删除
    @RequestMapping("/Adelete")
    public boolean Ade(String... arr){

            return  attStaffPerformanceSerice.removeBatchByIds(Arrays.asList(arr));
    }


    //部门绩效表查询
    @RequestMapping("/Adcx")
    public List<Map<String,Object>> Adcx(String dept,String name){
        List<Map<String,Object>> list=attStaffPerformanceSerice.Adcx(new QueryWrapper<AttStaffPerformance>().
                le("a.examination_score",name.equals("S")?100:name.equals("A")?89:name.equals("B")?79:name.equals("C")?69:name.equals("D")?59:100).
                ge("a.examination_score",name.equals("S")?90:name.equals("A")?80:name.equals("B")?70:name.equals("C")?60:name.equals("D")?50:0)
                .like(dept!=null,"a.dept_id",dept));
        return  list;
    }


}
